package com.yuqiangz.spring5.baseannotation.service;

import com.yuqiangz.spring5.baseannotation.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 赵雨强
 * @create 2021/7/21 7:57
 * @description
 * //在注解里面value属性值可以省略不写，
 * //默认值是类名称，首字母小写
 * //UserService -- userService
 * //@Component(value = "userService")  //<bean id="userService" class=".."/>
 */
@Service
public class UserService {

    @Value(value = "abc")
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    //定义dao类型属性
    //不需要添加set方法
    //添加注入属性注解
//    @Autowired  //根据类型进行注入
//    @Qualifier(value = "userDaoImpl1") //根据名称进行注入
//    private UserDao userDao;
    //@Resource  //根据类型进行注入



    @Resource(name = "userDaoImpl1")
    private UserDao userDao;


    public void add() {
        System.out.println("service add......."+name);
        userDao.add();
        System.out.println(getName());
    }
}
